package com.stox.ui.javafx.charting.widget;

import java.util.Locale;

import javafx.scene.control.ComboBox;
import javafx.util.StringConverter;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.stox.dto.enumeration.Span;

@Component
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class SpanComboBox extends ComboBox<Span>{

	public SpanComboBox() {
		getItems().addAll(Span.values());
		setId("span-combo-box");
	}
	
	@Autowired
	public void setMessageSource(final MessageSource messageSource){
		setConverter(new StringConverter<Span>(){
			@Override
			public Span fromString(String arg0) {
				return null;
			}
			
			@Override
			public String toString(Span span) {
				return messageSource.getMessage(span.getCode(), null, Locale.getDefault());
			}
		});
	}
	
}
